package tests;


import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import exceptions.InvalidItemCategoryException;
import exceptions.InvalidItemNameException;

import root.item.Item;
import root.user.User;
import strategy.AbstractStrategyFactory;

public class ItemTest {
	
	final String username = "testclass";
	final String name = "blabla";
	final String wrongUsername = "LOL";
	final String wrongName = "LOL";
	private String address = "oi";
	Item item;
	String description;
	String id;
	User user;
	String categoriaLivro = "Livro";
	
	@Before
	public void setUp() throws Exception {
		description = "blabla";
		id = "01";
		user = new User(username, name, address,AbstractStrategyFactory.getInstance());
		item = new Item(name, description, categoriaLivro, id,user);
	}
	
	@Test
	public void testConstructor(){
		Assert.assertEquals(item.getName(), name);
	}
	
	@Test
	public void testConstructor2(){
		Assert.assertEquals(item.getDescription(), description);
	}
	
	@Test
	public void testConstructor3(){
		Assert.assertEquals(item.getCategory(), categoriaLivro);
	}
	
	@Test(expected=InvalidItemNameException.class)
	public void testConstructor4() throws InvalidItemNameException, InvalidItemCategoryException{
		item = new Item(null, description, categoriaLivro, id,user);
	}
	
	@Test(expected=NullPointerException.class)
	public void testConstructor5() throws InvalidItemNameException, InvalidItemCategoryException{
		item = new Item(name, null, categoriaLivro, id,user);
	}
	
	@Test(expected=InvalidItemCategoryException.class)
	public void testConstructor6() throws InvalidItemNameException, InvalidItemCategoryException{
		item = new Item(name, description, null, id,user);
	}
	
	@Test(expected=InvalidItemNameException.class)
	public void testConstructor7() throws InvalidItemNameException, InvalidItemCategoryException{
		item = new Item("", description, categoriaLivro, id,user);
	}
	
	@Test(expected=NullPointerException.class)
	public void testSetName(){
		item.setName(null);
	}
	
	@Test(expected=NullPointerException.class)
	public void testSetDescription(){
		item.setDescription(null);
	}
	
	@Test(expected=NullPointerException.class)
	public void testSetCategory(){
		item.setCategory(null);
	}
	
	@Test
	public void testEquals() throws InvalidItemNameException, InvalidItemCategoryException{
		String id2 = "02";
		Item newItem = new Item(name, description, categoriaLivro,id2,user);
		Assert.assertNotSame(item, newItem);
	}
	
	@Test
	public void testEquals2(){
		Assert.assertEquals(item, item);
	}

}
